(defun calc (lst)
    (if (atom lst)
        (if (numberp lst)
            lst
            'Error.)
        (if (eql (car lst) '+)
            (add (cdr lst))
            (if (eql (car lst) '-)
                (sub (cdr lst))
                (if (eql (car lst) '*)
                    (mul (cdr lst))
                    (if (eql (car lst) '/)
                        (div (cdr lst))
                        'Error.))))))

(defun add (lst)
    (if (atom lst)
        0
        (if (numberp (car lst))
            (+ (car lst) (add (cdr lst)))
            (if (consp (car lst))
                (if (not (null (cdr lst)))
                    (+ (calc (car lst)) (add (cdr lst)))
                    (calc (car lst)))
                0))))

(defun sub (lst)
    (if (atom lst)
        0
        (if (numberp (car lst))
            (- (car lst) (sub (cdr lst)))
            (if (consp (car lst))
                (if (not (null (cdr lst)))
                    (+ (calc (car lst)) (sub (cdr lst)))
                    (calc (car lst)))
                0))))

(defun mul (lst)
    (if (atom lst)
        1
        (if (numberp (car lst))
            (* (car lst) (mul (cdr lst)))
            (if (consp (car lst))
                (if (not (null (cdr lst)))
                    (* (calc (car lst)) (mul (cdr lst)))
                    (calc (car lst)))
                1))))

(defun div (lst)
    (if (atom lst)
        1
        (if (numberp (car lst))
            (/ (car lst) (div (cdr lst)))
            (if (consp (car lst))
                (if (not (null (cdr lst)))
                    (* (calc (car lst)) (div (cdr lst)))
                    (calc (car lst)))
                1))))

(defun start ()
    (format T "~% > ")
    (let ((input (read)))
        (if (or (equal input '(exit))
                (equal input '(quit)))
            0
            (and (write (calc input))
                 (start)))))

(format T "Haceau-Calculator Lisp Editor v1.0.0")
(start)